package com.yzkj.cpjxc.business.framework.utils;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

import java.io.IOException;


/**
 * 获取类路径下面指定文件的绝对路径
 */
public class ClassPathResourceUtils {

	/**
	 * 根据文件名获取文件的绝对路径
	 */
	public static String getFilePath(String fileName) throws IOException {
		Resource resource = new ClassPathResource(fileName);
		return resource.getURL().getPath();
	}
	
	public static String getResourceByPath(String path) throws IOException {
		if (path !=null && path.startsWith("/")) {
			path = path.substring(1);
		}
		String absolutePath = new FileSystemResource(path).getURL().getPath();
		
		return absolutePath;
	}
	
}

